# coding:utf-8
# 主界面

import glog, glb
import account_mgr, role_mgr, event_mgr, car_mgr, mission_mgr, skill_mgr, item_mgr


# 全部信息
def on_get_main_data (params, account, role):
	glog.log('on_get_main_data ' + repr(params))
	
	data = {
		'player' : _get_player_info(role),
		'car_data' : _get_car_data(role),
		'mission_data' : _get_mission_data(role),
		'item_data' : _get_item_data(role),
	}
	glog.log('on_get_main_data return:'+ repr(data))
	return glb.return_ok(data)


# 玩家信息
def on_get_self_info (params, account, role):
	glog.log('on_get_self_info ' + repr(params))
	
	data = {
		'player' : _get_player_info(role),
	}
	return glb.return_ok(data)


def _get_player_info(role):
	player = {
		'name'	: role.name,
		'race'	: role.race,
		'level'	: role.level,
		'exp'	: role.exp,
		'exp_max'	: role.get_exp_max(),
		'money' : 99,
		'gold' : 99,
		'energy' : 99,
	}
	return player


# 玩家tank数据
def on_get_car_data (params, account, role):
	glog.log('on_get_car_data ' + repr(params))

	data = {
		'car_data' : _get_car_data(role),
	}
	return glb.return_ok(data)


def _get_car_data(role):
	cars = car_mgr.get_cars_by_owner(role.id)
	res = {}
	for car in cars:
		res[car.id] = car.to_dictionary()
	return res


# 关卡数据
def on_get_mission_data (params, account, role):
	glog.log('on_get_mission_data ' + repr(params))

	data = {
		'mission_data' : _get_mission_data(role),
	}
	return glb.return_ok(data)


def _get_mission_data(role):
	res = mission_mgr.get(role.id)
	if res is None: res = {}
	return res


# 道具数据
def on_get_item_data (params, account, role):
	glog.log('on_get_item_data ' + repr(params))

	data = {
		'item_data' : _get_item_data(role),
	}
	return glb.return_ok(data)


def _get_item_data(role):
	res = item_mgr.get_items_by_owner(role.id)
	if res is None: res = {}
	return res
